package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author zzw
 * @date 2025/5/16
 * @description 用户Mapper
 */
@Mapper
public interface UserMapper {
    // 根据id查询用户
    @Select("select * from user where id = #{id}")
    User getById(Long id);

    // 根据id查询今日用户
    List<User> getByIdsToday(@Param("usersIds") List<Long> usersIds);

    // 获取所有指定时间范围内的用户
    @MapKey("create_date")
    List<Map<String, Object>> getUserStatistics(LocalDate begin, LocalDate end);

    Integer countByMap(Map map);

    // 根据openid查询用户
    @Select("select * from user where openid = #{openid}")
    User getByOpenid(String openid);

    @Insert("insert into user (openid, name, phone, sex,id_number, avatar, create_time) " +
            "values (#{openid},#{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})"
    )
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);
}
